<?php
include("pdo.php");

$courses = json_decode(file_get_contents("http://www.cs.helsinki.fi/u/tkairi/rajapinta/courses.json"),true);
$courses = $courses["courses"];

foreach($courses as &$course)
{
	$stmt = $pdo->prepare("INSERT INTO COURSES (NAME,CREDITS) VALUES (?,?) RETURNING ID");
	$stmt->execute(array($course["course"],0));
	
	$id = $stmt->fetchObject()->id;
	
	$stmt = $pdo->prepare("INSERT INTO INSTANCES (COURSE,TEACHER,START_DATE,END_DATE) VALUES (?,?,?,?)");
	$stmt->execute(array($id,null,$course["start_date"],$course["end_date"]));
}

echo "Onnistui!";

?>
